package cn.llssit.mapper;

import cn.llssit.domain.Movie;
import cn.llssit.domain.MovieSearch;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: Lesan
 * @Date: 2020-06-21
 */
public interface MovieMapper {
    @Update("UPDATE movie SET `show` = #{show} WHERE id = #{id}")
    void updateShowState(int show,int id);

    @Update("UPDATE movie SET name=#{name},type=#{type},grade=#{grade},want=#{want},locate=#{locate},duration=#{duration},date=#{date},showloc=#{showloc},poster=#{poster},box=#{box},main_actor=#{main_actor},state=#{state},`show`=#{show},`language`=#{language},`describe`=#{describe} WHERE id=#{id}")
    void updateMovie(Movie movie);

    @Delete("DELETE FROM movie WHERE id=#{id}")
    void deleteMovie(Integer id);

    @Select("SELECT * FROM movie ORDER BY box DESC,want DESC")
    List<Movie> selectAll();

    @Select("SELECT * FROM movie")
    List<MovieSearch> selectAllForSearch();

    @Select("SELECT * FROM movie WHERE state=#{state}")
    List<Movie> selectByState(String state);

    @Select("SELECT * FROM movie WHERE name=#{name}")
    List<Movie> selectByName(String name);

    @Select("SELECT * FROM movie WHERE id=#{id}")
    Movie selectById(Integer id);

    @Insert("INSERT INTO movie VALUES(null,#{name},#{type},#{grade},#{want},#{locate},#{duration},#{describe},#{date},#{showloc},#{poster},#{box},#{main_actor},#{state},#{show},#{language})")
    void addMovie(Movie movie);

}
